#written by Martin Schwentner, April 1st, 2016
#this script changes the header, leaving only the species name in [], it changes the files itself and does not create a new files!

import fileinput, glob, string, sys, os

filename = glob.glob("*.muscle.fasta")
for line in fileinput.input(filename, inplace=True):
    if line.startswith('>'):
        species_name=line[line.find("[")+1:line.find("]")]   #saves all between [ and ] to species_name in line
        print line.replace(line, '>' + species_name)
    else:
        print line,
    



